﻿namespace EasyWeb
{
    using System;
    using System.ComponentModel.DataAnnotations;
    using EasyWeb.Validation;

    public class EWSelectionItemDefinition
    {
        private readonly EWStateBag stateBag = new EWStateBag();

        public Guid Id
        {
            get { return this.StateBag.Get<Guid>("Id"); }
            set { this.StateBag.Set("Id", value); }
        }

        [Display(ResourceType = typeof(EWFieldDefinitionResources), Name = "SelectionItemDefinition_SelectionDefinitionId")]
        public Guid SelectionDefinitionId
        {
            get { return this.StateBag.Get<Guid>("SelectionDefinitionId"); }
            set { this.StateBag.Set("SelectionDefinitionId", value); }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_Key")]
        [Required]
        [StringLength(60)]
        [EWNameValidation]
        public string Key
        {
            get { return this.StateBag.Get<string>("Key"); }
            set
            {
                EWGuard.IsNotNullOrEmpty(value, "value");
                this.StateBag.Set("Key", value);
            }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_Value")]
        public EWText Value
        {
            get { return this.StateBag.Get<EWText>("Value", () => new EWText()); }
            set
            {
                EWGuard.IsNotNull(value, "value");
                this.StateBag.Set("Value", value);
            }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_CreatedBy")]
        public string CreatedBy
        {
            get { return this.StateBag.Get<string>("CreatedBy"); }
            set
            {
                EWGuard.IsNotNullOrEmpty(value, "value");
                this.StateBag.Set("CreatedBy", value);
            }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_Created")]
        public DateTime Created
        {
            get { return this.StateBag.Get<DateTime>("Created"); }
            set { this.StateBag.Set("Created", value); }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_ModifiedBy")]
        public string ModifiedBy
        {
            get { return this.StateBag.Get<string>("ModifiedBy"); }
            set
            {
                EWGuard.IsNotNullOrEmpty(value, "value");
                this.StateBag.Set("ModifiedBy", value);
            }
        }

        [Display(ResourceType = typeof(EWEntityDefinitionResources), Name = "SelectionItemDefinition_Modified")]
        public DateTime Modified
        {
            get { return this.StateBag.Get<DateTime>("Modified"); }
            set { this.StateBag.Set("Modified", value); }
        }

        public byte[] Timestamp
        {
            get { return this.StateBag.Get<byte[]>("Timestamp"); }
            set
            {
                EWGuard.IsNotNull(value, "value");
                this.StateBag.Set("Timestamp", value);
            }
        }

        public EWStateBag StateBag
        {
            get { return this.stateBag; }
        }
    }
}
